-
Notifications
You must be signed in to change notification settings - Fork 612
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add wsclient library to ecs-agent module #3690
Conversation
Linux / Linux unit tests check is failing at the moment, just want to confirm is this PR ready for review or currently still WIP? |
|
@@ -35,10 +35,11 @@ import ( | |||
"time" | |||
|
|||
"github.com/aws/amazon-ecs-agent/agent/config" | |||
"github.com/aws/amazon-ecs-agent/agent/utils" | |||
"github.com/aws/amazon-ecs-agent/agent/utils/cipher" | |||
"github.com/aws/amazon-ecs-agent/agent/wsclient/wsconn" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Shouldn't imports of "github.com/aws/amazon-ecs-agent/agent/wsclient/wsconn" be updated to "github.com/aws/amazon-ecs-agent/ecs-agent/wsclient/wsconn" then we can remove the unused files in agent/wsclient/wsconn
, right? (i.e., like what we've done with agent/utils/cipher
and agent/utils/httpproxy
)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I do not think it makes sense to switch just wsconn imports to ecs-agent/wsclient. The plan is to plug in the ecs-agent/wsclient with ecs-agent/tcs and ecs-agent/acs, and once we have the confidence in testing, we would completely remove the agent/wsclient package. It made sense to move the utils to avoid the cyclic dependency issue between agent and ecs-agent.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I was just thinking since the files in agent/wsclient/wsconn
and ecs-agent/wsclient/wsconn
are identical, we could just have a single one living in ecs-agent/
to refer to as a source of truth since we will be removing agent/wsclient/wsconn
in the future anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once we have the confidence in testing, we would completely remove the agent/wsclient package
do we have a TODO for this anywhere (in code or in a tracking ticket)?
Reply from RichaGangwar:
Yes Ray, Thats the plan. As part of tcs and acs shared lib, we will integrate this new wsclient lib in the clients. And once well tested, we will remove the agent/wsclient. There isn't any TODO right now. Will add it in description to keep track of it. Thank you :)
ecs-agent/wsclient/client.go
Outdated
// AgentConfig is a subset of agent's config. Since this requires agent specific information, | ||
// making this as a struct to be passed from the individual agents while using the wsclient shared lib. | ||
// The agent where the field is not applicable can be left empty | ||
type AgentConfig struct { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we rename this to something that makes it more distinguishable from the original agent config (maybe something along the lines ofMinimalAgentConfig
, or WSClientAgentConfigs
)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. I will update it.
timeoutDialer := &net.Dialer{Timeout: wsConnectTimeout} | ||
tlsConfig := &tls.Config{ServerName: parsedURL.Host, InsecureSkipVerify: cs.cfg.AcceptInsecureCert, MinVersion: tls.VersionTLS12} | ||
|
||
//TODO: In order to get rid of the check - |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need to get rid of this check as part of this PR? It seems to be specific to Docker, and I don't think we want anything tied to or specific to Docker in the ecs-agent module.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, ideally I want to get rid of the check. I had a discussion with multiple folks and able to resolve few other such checks. I am preparing to doc to deal with these two checks. Once everyone agrees on the strategy, we can remove these checks as well. I had raised the PR so that ACS is unblocked, as driving consensus is taking some time.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good, will look forward to this in a followup PR then. If not already, let's make sure we're tracking this internally.
ecs-agent/wsclient/client.go
Outdated
// ClientServerImpl wraps commonly used methods defined in ClientServer interface. | ||
type ClientServerImpl struct { | ||
// cfg is the subset of user-specified runtime configuration | ||
cfg *AgentConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be capitalized to be exported.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for pointing out. Will fix this.
ecs-agent/wsclient/client.go
Outdated
|
||
"github.com/aws/aws-sdk-go/aws/credentials" | ||
"github.com/aws/aws-sdk-go/private/protocol/json/jsonutil" | ||
"github.com/cihub/seelog" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we want to be using github.com/aws/amazon-ecs-agent/ecs-agent/logger for any logging in ecs-agent/
. I see we are already using it for some of the logging in this file, could we update to make sure we’re using that and not seelog directly in ecs-agent/
(whether that be in this PR or a future one)?
// by backend. It allows for bidirectional communication and acts as both a | ||
// client-and-server in terms of requests, but only as a client in terms of | ||
// connecting. | ||
package wsclient |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Periodic timeout/disconnection of WebSocket connections seems to be missing from this PR, let’s make sure to add that in if we can.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Currently, the timeouts are initiated by individual components using the library, i.e. ACS and TACS have their own implementation of timeouts. I had not accounted for that as part of wsclient library, hence it's missing from this PR. Is that something we want to unify?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I believe we decided that we want to have the same logic for refreshing our websocket connection across all our websocket connections (i.e., ACS and TACS websocket connections). I'll reach out to you offline and point you in the direction of these previous discussions.
21f2333
to
f9488b3
Compare
ecs-agent/utils/sign_http_request.go
Outdated
signer := v4.NewSigner(creds) | ||
_, err := signer.Sign(req, body, service, region, time.Now()) | ||
if err != nil { | ||
seelog.Warnf("Signing HTTP request failed: %v", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be updated to use logger instead of seelog as well (per this previous comment).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thank you for pointing out.
|
||
// ExitTerminal indicates the agent run into error that's not recoverable | ||
// no need to restart | ||
ExitTerminal = 5 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we move the exitcodes package to /ecs-agent? Perhaps in a fast follow-up PR, if not this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Will move it as a follow-up PR. This is already quite bulky. But thank you for pointing out.
ecs-agent/wsclient/client.go
Outdated
} | ||
|
||
// RespondFunc specifies a function callback that can be used by the | ||
// RequestResonder to respond to requests. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: typo, RequestResonder -> RequestResponder
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks.
// ClientServerImpl wraps commonly used methods defined in ClientServer interface. | ||
type ClientServerImpl struct { | ||
// Cfg is the subset of user-specified runtime configuration | ||
Cfg *WSClientMinAgentConfig |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Cfg need to be exported?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would need to be populated by the ACS/TACS libraries. So it needs to be exported.
ecs-agent/wsclient/client.go
Outdated
io.Closer | ||
} | ||
|
||
// AgentConfig is a subset of agent's config. Since this requires agent specific information, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: "WSClientMinAgentConfig is a subset[...]"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thanks.
ecs-agent/wsclient/client.go
Outdated
// messages from an active connection. | ||
func (cs *ClientServerImpl) ConsumeMessages(ctx context.Context) error { | ||
// Since ReadMessage is blocking, we don't want to wait for timeout when context gets cancelled | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: weird newline
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
ecs-agent/wsclient/client_factory.go
Outdated
// ClientFactory interface abstracts the method that creates new ClientServer | ||
// objects. This is helpful when writing unit tests. | ||
type ClientFactory interface { | ||
New(url string, credentialProvider *credentials.Credentials, rwTimeout time.Duration) ClientServer |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This needs to be updated to include a *wsclient.WSClientMinAgentConfig
parameter in the function signature.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed. Thank you for pointing it out. :)
) | ||
|
||
// GetMockServer returns a mock websocket server that can be started up as TLS or not. | ||
// TODO replace with gomock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this TODO doable within this PR?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This mockServer is heavily used in all existing test cases. Maybe it can be picked up in a separate PR. But it would need good amount of rewrite.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this isn't something we can pull in from our mockgen process in the agent. Ideally all of our mocks are generated. (We'll follow up offline).
ecs-agent/wsclient/client_test.go
Outdated
//test for DecodeConnectionError | ||
//use WriteCloseMessage | ||
|
||
//send httpResponse in Connect() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are there missing tests here on L349-L352, or what are these comments?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missed removing the comments. I was using it while writing new tests to ensure the coverage requirements are met. Will remove them in latest commit.
ecs-agent/wsclient/client_test.go
Outdated
waitForRequests.Wait() | ||
} | ||
|
||
func getClientServer(url string, msgType []interface{}) *ClientServerImpl { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we change this name to be dummyClientServer
or testClientServer
or similar? That seems a lot more clear to me.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Done.
ecs-agent/wsclient/client_test.go
Outdated
} | ||
|
||
func getClientServer(url string, msgType []interface{}) *ClientServerImpl { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spacing
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed.
ecs-agent/wsclient/client_test.go
Outdated
|
||
// Close closes the underlying connection. Implement Close() in this file | ||
// as ClientServerImpl doesn't implement it. This is needed by the | ||
// TestSetReadDeadline* tests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's update comments to end with periods/have proper punctuation if they don't already
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Fixed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's do some commit squashing please. Overall, not seeing any major concerns!
Sure Soo. |
for { | ||
select { | ||
case <-ctx.Done(): | ||
// Close connection and wait for Read goroutine to finish |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we update our tests to cover this code path (i.e., L491-L495)? This is a major change from our current agent/wsclient/client.go
, and we currently don't have any tests that validate this behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sure. Added.
}() | ||
// Cancel the context. | ||
cancel() | ||
assert.EqualError(t, <-messageError, "context canceled") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit (not blocking, can be added in a followup PR so that this PR can get merged and unblock other work ASAP):
Can we use context.Canceled.Error()
here instead of hardcoding "context canceled" (i.e., similar to what we do on L283)?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Approved under the agreement that we will fast follow with a PR to include periodic timeout/disconnection of websocket connections logic as part of the wsclient itself (per this comment thread) and that we will squash commits before merging.
8cfa5a0
to
6cc9959
Compare
f04f424
to
14407ee
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the description to highlight TODOs from code and from comments so we can track these in our release process?
@@ -35,10 +35,11 @@ import ( | |||
"time" | |||
|
|||
"github.com/aws/amazon-ecs-agent/agent/config" | |||
"github.com/aws/amazon-ecs-agent/agent/utils" | |||
"github.com/aws/amazon-ecs-agent/agent/utils/cipher" | |||
"github.com/aws/amazon-ecs-agent/agent/wsclient/wsconn" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
once we have the confidence in testing, we would completely remove the agent/wsclient package
do we have a TODO for this anywhere (in code or in a tracking ticket)?
Reply from RichaGangwar:
Yes Ray, Thats the plan. As part of tcs and acs shared lib, we will integrate this new wsclient lib in the clients. And once well tested, we will remove the agent/wsclient. There isn't any TODO right now. Will add it in description to keep track of it. Thank you :)
) | ||
|
||
// GetMockServer returns a mock websocket server that can be started up as TLS or not. | ||
// TODO replace with gomock |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this isn't something we can pull in from our mockgen process in the agent. Ideally all of our mocks are generated. (We'll follow up offline).
"github.com/aws/amazon-ecs-agent/agent/version" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/cipher" | ||
"github.com/aws/amazon-ecs-agent/ecs-agent/utils/httpproxy" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
will we be able to remove https://github.com/aws/amazon-ecs-agent/blob/master/agent/utils/httpproxy in a future pr?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, agent/utils/httpproxy is already moved to ecs-agent/utils/httpproxy as part of this PR. Is that what you are referring to Ray?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you update the description to highlight TODOs from code and from comments so we can track these in our release process?
Sure Ray. |
Summary
Add wsclient library to ecs-agent
Implementation details
TODOs to be handled in future PRs:
Testing
Unit tested with existing tests in wsclient
Unit tested agent with make test
New tests cover the changes: no
Description for the changelog
Add wsclient library to ecs-agent module.
Licensing
By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.